//
//  ChooseSenceCell.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 10/22/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "ChooseSenceCell.h"

@implementation ChooseSenceCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self makeViews];
    }
    return self;
}

-(void)makeViews
{
    self.typeLB = [UILabel initLabelText:@"拍摄类型" andRect:CGRectMake(0,0,70,46+29+9) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0x4a4a4a) andTextAlignment:NSTextAlignmentCenter];
    _typeLB.tag = 101;
    
    self.mScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(70, 0, UI_SCREEN_WIDTH-70,46+28.5+9)];
    _mScrollView.showsHorizontalScrollIndicator = NO;
    _mScrollView.contentSize = CGSizeMake(UI_SCREEN_WIDTH-70,46+28.5+9);
    _mScrollView.tag = 102;
    
    [self.contentView addSubview:_typeLB];
    [self.contentView addSubview:_mScrollView];
}


-(void)setDataArray:(NSMutableArray *)dataArray
{
    if (_dataArray){
        _dataArray = nil;
    }
    _dataArray = [[NSMutableArray alloc] initWithArray:dataArray];
    
    for (UIButton * btn in [_mScrollView subviews]){
        if ([btn isKindOfClass:[btn class]]){
            [btn removeFromSuperview];
        }
    }
    
    for (int i =0;i<[_dataArray count];i++){
        
        UIButton * button = [UIButton initButton:CGRectMake(20+(60+15)*(i%3),9+(28.5+9)*(i/3),60,28.5) btnNorImage:LOADIMAGE(@"choosetaocan_nor@2x") btnDisableBtn:LOADIMAGE(@"choosetaocan_dis@2x") btnTitle:[_dataArray objectAtIndex:i][@"SceneName"] titleNorColor:UIColorFromRGB(0x4a4a4a) titleSelectColor:UIColorFromRGB(0x4a4a4a) titleFont:[UIFont systemFontOfSize:12]];
        button.tag = 1000+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [button setTitleColor:UIColorFromRGB(0x8c8c8c) forState:UIControlStateDisabled];
        [button setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateSelected];
        [button setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateHighlighted];
        button.adjustsImageWhenDisabled =NO;
        button.adjustsImageWhenHighlighted =NO;
        

        [_mScrollView addSubview:button];
        
        if ([[_dataArray objectAtIndex:i][@"PageType"] intValue]==4){
            self.brithTag = i+1000;
        }
    }
    
}

-(void)buttonClick:(UIButton *)button
{
    if (button.isSelected){
        return;
    }
    for (UIButton * btn in _mScrollView.subviews){
        if ([btn isKindOfClass:[UIButton class]]){
            btn.selected = button.tag == btn.tag?YES:NO;
        }
    }
    [_delegate chooseSence:[_dataArray objectAtIndex:button.tag-1000] andchooseindex:button.tag];
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
